#include "gui_app_main.h"

/**
* @brief APP事件
* @retval    None
*/
static void s_gui_app_led_btn_event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target(e);

    if (code == LV_EVENT_SHORT_CLICKED) /* 短按 */
    {
        /* 点亮LED灯 */
        gui_hw_led_ctrl(DEV_LED_ON);
    }
    else if (code == LV_EVENT_LONG_PRESSED) /* 长按 */
    {
        /* 熄灭LED灯 */
        gui_hw_led_ctrl(DEV_LED_OFF);
    }

    return;
}

lv_obj_t * gui_app_led_create(lv_obj_t *parent, void *user_data)
{
    /* 应用初始化 */
    lv_obj_t *obj = gui_app_common_init(parent, "app_led", NULL);

    static lv_style_t style_btn_led;

    lv_style_init(&style_btn_led);           // 初始化按钮样式
    lv_style_set_radius(&style_btn_led, 22); // 设置样式圆角弧度

    /* 创建一个按键 */
    lv_obj_t *btn_led = lv_btn_create(obj);
    lv_obj_set_size(btn_led, 100, 50);
    lv_obj_align(btn_led, LV_ALIGN_CENTER, 0, 0);
    lv_obj_add_style(btn_led, &style_btn_led, 0);
    lv_obj_add_event_cb(btn_led, s_gui_app_led_btn_event_cb, LV_EVENT_ALL, NULL);

    lv_obj_t *label_led = lv_label_create(btn_led);
    lv_label_set_text(label_led, "SWITCH");
    lv_obj_align_to(label_led, btn_led, LV_ALIGN_CENTER, 0, 0);

    /* 返回该应用的APP OBJ指针 */
    return obj;
}
